<template>
	<view>
		<view style="width: 90%;margin: 0 auto;">
			<u-search placeholder="搜索附近优惠卷" v-model="keyword" @change="search" :show-action="false"></u-search>
		</view>
		<al-goods-list :data="data" clickUrl="/pages/detail/index"></al-goods-list>
	</view>
</template>

<script>
	export default {
		data () {
			return {
				keyword: '',
				page: 0,
				length: 10,
				data: [],
				status: 'loadmore',
				dataLength: 0,
			}
		},
		onReachBottom() {
			// console.log('1111')
			if (this.dataLength < 10) return;
			this.status = 'loading';
			this.page = this.length;
			this.length = this.length + 10
			setTimeout(() => {
				this.getCouponList()
				if (this.length < 10) this.status = 'nomore';
				else this.status = 'loading';
			}, 2000)
		},
		onShow() {
			this.getCouponList()
		},
		methods: {
			search () {
				this.length = 10
				this.page = 0
				this.data = []
				this.$request('', '/api/app/coupon/goodslist', 'POST', {
					length: this.length,
					start: this.page,
					goods_name: this.keyword,
					subtitle_title: this.keyword,
					city: uni.getStorageSync('city') ? uni.getStorageSync('city') : '长沙市'
				}, {}).then(res => {
					for (let i in res.data) {
						this.data.push(res.data[i])
					}
					this.dataLength = res.data.length
					if (this.dataLength < 10) {
						this.status = 'nomore'
					}
				})
			},
			getCouponList() {
				this.length = 10
				this.page = 0
				this.$request('', '/api/app/coupon/goodslist', 'POST', {
					length: this.length,
					start: this.page,
					goods_name: this.keyword,
					subtitle_title: this.keyword,
					city: uni.getStorageSync('city') ? uni.getStorageSync('city') : '长沙市'
				}, {}).then(res => {
					for (let i in res.data) {
						this.data.push(res.data[i])
					}
					this.dataLength = res.data.length
					if (this.dataLength < 10) {
						this.status = 'nomore'
					}
				})
			}
		}
	}
</script>

<style>
</style>
